<?php

namespace Lib\Logic;

class WxcurlLogic{
    
    private $curlUrl;
    private $curlPost;
    private $curlData;
    
    //__get()方法用来获取私有属性
    private function __get($property_name)
    {
        if(isset($this->$property_name))
        {
            return($this->$property_name);
        }else
        {
            return(NULL);
        }
    }
    
    //__set()方法用来设置私有属性
    private function __set($property_name, $value)
    {
        $this->$property_name = $value;
    }
    
    public function wx_curl_exec(){
        $wxAPIResult = null;
        if ($this->curlPost){
            $wxAPIResult = $this->_curlPost();
        } else{
            $wxAPIResult = $this->_curlGet();
        }
        
        if ($wxAPIResult){
            return $wxAPIResult;
        } else{
            return false;
        }
        
    }
    
    private function _curlGet(){
        $ch = curl_init();
        $timeout = 5;
        curl_setopt ($ch, CURLOPT_URL, $this->curlUrl);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }
    
    private function _curlPost(){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_URL, $this->curlUrl);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->curlData);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }    
    
}

?>